package com.oa.business.org;

import com.alibaba.fastjson.JSON;
import com.oa.business.org.dto.DepartmentDto;
import com.oa.common.result.Result;
import com.oa.framework.org.department.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author cuichao
 */
@RestController
@RequestMapping("dept")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    @GetMapping("search")
    public Result search() {
        return Result.success(departmentService.loadDepartments());
    }

    @GetMapping("info/{id}")
    public Result info(@PathVariable Long id) {
        return Result.success(departmentService.getDepartmentIncludeDuties(id));
    }

    @PostMapping("add")
    public Result add(@RequestBody DepartmentDto departmentDto) {
        return Result.success(departmentService.addDepartment(departmentDto.transform()));
    }

    @PostMapping("edit")
    public Result edit(@RequestBody DepartmentDto departmentDto) {
        return Result.success(departmentService.updateDepartment(departmentDto.transform()));
    }

    @PostMapping("disable/{id}")
    public Result disable(@PathVariable Long id) {
        return Result.success(departmentService.disable(id));
    }

}
